package com.gxc.mall.common.util;

import java.io.Serializable;

/**
 * Rest 返回数据结构.
 *
 * @author 宫新程
 * @since 2019/3/31 13:08
 */
public class RestControllerResult<T> implements Serializable {

    private boolean success;

    private String errorMsg;

    private T data;

    public RestControllerResult() {
    }

    public RestControllerResult(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    public RestControllerResult(boolean success, String errorMsg, T data) {
        this.success = success;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public static <T> RestControllerResult<T> success(T data) {
        RestControllerResult<T> result = new RestControllerResult<>();
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static <T> RestControllerResult<T> error(String errorMsg) {
        RestControllerResult<T> result = new RestControllerResult<>();
        result.setSuccess(false);
        result.setErrorMsg(errorMsg);
        return result;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
